<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<style>
	#div1 {width: 100px; height: 100px; background: red; position: absolute;}
	
</style>
<script>
window.onload = function()
{
		var oDiv = document.getElementById('div1');
	
		var disX =0 ;
		var disY = 0;
	
		oDiv.onmousedown= function(ev)
		{
				//clientX clientY 鼠标坐标
				var oEvent = ev||event;
				disX = oEvent.clientX- oDiv.offsetLeft ;
				disY = oEvent.clientY -oDiv.offsetTop ;
				
			if (oDiv.setCapture)
				{
								//IE
								oDiv.onmousemove= function(ev)
								{
										var oEvent = ev||event;
										var left = oEvent.clientX - disX;
										var top = oEvent.clientY - disY;

										if(left<0)
										{
												left = 0;
										}

										if(top<0)
										{
												top = 0;
										}

										oDiv.style.left = left + 'px';
										oDiv.style.top = top + 'px';

								};

								oDiv.onmouseup = function()
								{
										oDiv.onmousemove =null;
										oDiv.onmouseup=null;
										oDiv.releaseCapture();
								};

								oDiv.setCapture();
								
				}else
					{
						//  ff, chrome
							document.onmousemove= function(ev)
							{
									var oEvent = ev||event;
									var left = oEvent.clientX - disX;
									var top = oEvent.clientY - disY;

									if(left<0)
									{
											left = 0;
									}

									if(top<0)
									{
											top = 0;
									}


									oDiv.style.left = left + 'px';
									oDiv.style.top = top + 'px';

							};

						document.onmouseup = function()
						{
								document.onmousemove =null;
								document.onmouseup=null;
						};				
						return false;
					}
			
		};
};
</script>
</head>

<body>
<div>dasaad</div>
<div>89jkjkj</div>
<div>llmmmm</div>
	<div id="div1">dsadsada</div>

</body>
</html>
